﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Streambolics.Web
{
    public class HttpQueryJobProcessor : JobProcessor<HttpQueryJob>
    {
        private WebBrowser _Browser = new WebBrowser ();

        public HttpQueryJobProcessor ()
        {
            _Browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler (_Browser_DocumentCompleted);
        }

        void _Browser_DocumentCompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            Current.Text = _Browser.DocumentText;
            Complete ();
        }

        protected override void Process (HttpQueryJob aJob)
        {
            _Browser.Url = new Uri (aJob.Url);
        }

        protected override void DoStart ()
        {
            DeclareStarted ();
        }

        protected override void DoStop ()
        {
            DeclareStopped ();
        }

        protected override bool IsBusy ()
        {
            return base.IsBusy () || _Browser.IsBusy;
        }
    }
}
